Skip to content

Refactor source layout boundaries#25

Merged
mmkal merged 1 commit into
mainfrom
refactor/src-layout-boundaries
May 27, 2026
Merged

Refactor source layout boundaries#25
mmkal merged 1 commit into
mainfrom
refactor/src-layout-boundaries

Conversation

@mmkal
Copy link
Copy Markdown
Contributor

@mmkal mmkal commented May 27, 2026

Summary

This keeps the public captun library surface in src/index.ts, moves runtime-specific entrypoints and the self-hosted Tunnel Gateway under src/server, and leaves hosted product policy under src/hosted.

The root library now owns the shared gateway connect constants and fetcher capability helpers directly. The broader hosted reserved-name list is hosted-only, while the self-hosted gateway only reserves the captun and gateway labels that can collide with custom gateway hostnames.

CLI tunnel retries now reuse one generated client token for any gateway, and createCaptunTunnel() returns only the gateway-confirmed tunnel payload rather than falling back to the client token.

Validation

  • pnpm run typecheck
  • pnpm run build
  • pnpm run lint
  • pnpm run format:check
  • pnpm test

Note

Medium Risk
Medium risk from a wide file move plus changed tunnel token return semantics and reserved-name behavior on hosted vs self-hosted gateways; mitigated by updated tests and lint boundaries.

Overview
This PR restructures the repo so the public captun API stays in src/index.ts (Cap'n Web tunnel client, connect query constants, fetcher helpers, randomConnectToken), while runtime adapters and the self-hosted Cloudflare gateway move under src/server/ (worker.ts, tunnel-addressing.ts, node/bun/deno). Hosted-only policy (broad reserved tunnel names, captun.sh site routing) lives under src/hosted/, with the self-hosted worker only blocking captun and gateway on custom-domain deploys.

Package and deploy paths now point at src/server/worker.ts / dist/server/worker.js. Oxlint enforces that root src/** may import only capnweb, with exceptions for CLI, server, hosted, tests, and examples.

Connect/token behavior changes: createCaptunTunnel always attaches a generated token on connect when none is passed, but returns only what the gateway sends in ready (no merging in a client token). The CLI generates one token per session and reuses it across retries for any gateway, not only captun.sh.

Docs, Miniflare fixtures, and tests were updated for the new layout and the split reserved-name rules.

Reviewed by Cursor Bugbot for commit 6963beb. Bugbot is set up for automated code reviews on this repo. Configure here.

@mmkal mmkal merged commit e321335 into main May 27, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant